#!/bin/bash
HIVEPATH=/usr/bin
#Created by Turk 2018-05-19

DATE=`date +"%Y%m%d"`
TAGERPATH=/oradata/ftpdata

FTP=132.121.126.87
FTPPORT=2121
FTPUSER=wbahc
FTPPASSWORD=wbahc%!59
SOURCEPATH=/

WORKPATH=/home/ftpuser/work
LOGFILE=${WORKPATH}/log/LoadEpg_${DATE}.log


#DATEM=`date -d '1 day ago' +%Y%m`
#DATED=`date -d '1 day ago' +%Y%m%d`


EXT=txt

ftptransfer()
{
	DATE=$1
	DATAFILE=*${DATE}.txt
	
	echo "ftp->${FTP}:${FTPPORT}"
	echo "sourcepath:${SOURCEPATH}"
	echo "tagetpath:${TAGERPATH}"
	echo "datafile:${DATAFILE}"
	ftp -n << EOFa
	open ${FTP} ${FTPPORT}
	user ${FTPUSER} ${FTPPASSWORD}
	cd ${SOURCEPATH}
	lcd ${TAGERPATH}
	bin
	prompt
	mget ${SOURCEPATH}/${DATAFILE}
	quit
EOFa
}


function main()
{
	if [ $# -lt 1 ]; then
		echo `date +"%Y-%m-%d %H:%M:%S"`  "Usage:<DATE>"
		exit 1
	fi
	
	PARA=$1
    echo "main start..."
	#echo `date` "===========iptv_ftp_epgbehavior_to_mysql ${TABLENAME} start===========" >> ${LOGFILE}
	
    ftptransfer $PARA
	echo `date` "get files from ftp servers." >> ${LOGFILE}
}


######################
#    main procedure
######################
main "$@"
exit $?
